** STATA code for Greenhill Mosley Prakash (2009) "Trade-Based Diffusion of Labor Rights: A Panel Study, 1986-2002"

** Greenhilletal_APSR09
insheet using "GMP replication data.csv" , comma clear

** Prep:

	** generate 1-year lags:
	gen laggeddv=laborrights[_n-1] if imfcode==imfcode[_n-1]
	gen tradecontext1=tradecontext[_n-1] if imfcode==imfcode[_n-1]
	gen fdiflows1=fdiflows[_n-1] if imfcode==imfcode[_n-1]
	gen fdistock1=fdistock[_n-1] if imfcode==imfcode[_n-1]
	gen trade1=trade[_n-1] if imfcode==imfcode[_n-1]
	gen ngos1=ngos[_n-1] if imfcode==imfcode[_n-1]
	gen income1=income[_n-1] if imfcode==imfcode[_n-1]
	gen population1=population[_n-1] if imfcode==imfcode[_n-1]
	gen democracy1=democracy[_n-1] if imfcode==imfcode[_n-1]
	gen civilwar1=civilwar[_n-1] if imfcode==imfcode[_n-1]
	gen lawtradecontext1=lawtradecontext[_n-1] if imfcode==imfcode[_n-1]
	gen practicetradecontext1=practicetradecontext[_n-1] if imfcode==imfcode[_n-1]
	gen hardpta1=hardpta[_n-1] if imfcode==imfcode[_n-1]
	gen softpta1=softpta[_n-1] if imfcode==imfcode[_n-1]
	gen exports1=exports[_n-1] if imfcode==imfcode[_n-1]
	gen lawpos1=lawpos[_n-1] if imfcode==imfcode[_n-1]
	gen practicepos1=practicepos[_n-1] if imfcode==imfcode[_n-1]
	gen wlawpos1=wlawpos[_n-1] if imfcode==imfcode[_n-1]
	gen wpracticepos1=wpracticepos[_n-1] if imfcode==imfcode[_n-1]
	gen lawinstrument1=lawinstrument[_n-1] if imfcode==imfcode[_n-1]
	gen practiceinstrument1=practiceinstrument[_n-1] if imfcode==imfcode[_n-1]
	gen lawinstb1=lawinstb[_n-1] if imfcode==imfcode[_n-1]
	gen practiceinstb1=practiceinstb[_n-1] if imfcode==imfcode[_n-1]
	gen wlanglaw1=wlanglaw[_n-1] if imfcode==imfcode[_n-1]
	gen wlangprac1=wlangprac[_n-1] if imfcode==imfcode[_n-1]
	gen wrellaw1=wrellaw[_n-1] if imfcode==imfcode[_n-1]
	gen wrelprac1=wrelprac[_n-1] if imfcode==imfcode[_n-1]
	gen wcollaw1=wcollaw[_n-1] if imfcode==imfcode[_n-1]
	gen wcolprac1=wcolprac[_n-1] if imfcode==imfcode[_n-1]
	gen igo1=         igo[_n-1] if imfcode==imfcode[_n-1]
	gen ingo1=       ingo[_n-1] if imfcode==imfcode[_n-1]
	gen capopen1= capopen[_n-1] if imfcode==imfcode[_n-1]
	gen civlib1 =  civlib[_n-1] if imfcode==imfcode[_n-1]
	
	
	** generate 2-year lags:
	gen tradecontext2=tradecontext[_n-2] if imfcode==imfcode[_n-2]
	gen fdiflows2=fdiflows[_n-2] if imfcode==imfcode[_n-2]
	gen fdistock2=fdistock[_n-2] if imfcode==imfcode[_n-2]
	gen trade2=trade[_n-2] if imfcode==imfcode[_n-2]
	gen ngos2=ngos[_n-2] if imfcode==imfcode[_n-2]
	gen income2=income[_n-2] if imfcode==imfcode[_n-2]
	gen population2=population[_n-2] if imfcode==imfcode[_n-2]
	gen democracy2=democracy[_n-2] if imfcode==imfcode[_n-2]
	gen civilwar2=civilwar[_n-2] if imfcode==imfcode[_n-2]
	gen lawtradecontext2=lawtradecontext[_n-2] if imfcode==imfcode[_n-2]
	gen practicetradecontext2=practicetradecontext[_n-2] if imfcode==imfcode[_n-2]
	gen hardpta2=hardpta[_n-2] if imfcode==imfcode[_n-2]
	gen softpta2=softpta[_n-2] if imfcode==imfcode[_n-2]
	gen exports2=exports[_n-2] if imfcode==imfcode[_n-2]
	gen wlawpos2=wlawpos[_n-2] if imfcode==imfcode[_n-2]
	gen wpracticepos2=wpracticepos[_n-2] if imfcode==imfcode[_n-2]
	gen lawinstrument2=lawinstrument[_n-2] if imfcode==imfcode[_n-2]
	gen practiceinstrument2=practiceinstrument[_n-2] if imfcode==imfcode[_n-2]
	gen lawinstb2=lawinstb[_n-2] if imfcode==imfcode[_n-2]
	gen practiceinstb2=practiceinstb[_n-2] if imfcode==imfcode[_n-2]
	gen wlanglaw2=wlanglaw[_n-2] if imfcode==imfcode[_n-2]
	gen wlangprac2=wlangprac[_n-2] if imfcode==imfcode[_n-2]
	gen wrellaw2=wrellaw[_n-2] if imfcode==imfcode[_n-2]
	gen wrelprac2=wrelprac[_n-2] if imfcode==imfcode[_n-2]
	gen wcollaw2=wcollaw[_n-2] if imfcode==imfcode[_n-2]
	gen wcolprac2=wcolprac[_n-2] if imfcode==imfcode[_n-2]	
	gen igo2=         igo[_n-2] if imfcode==imfcode[_n-2]
	gen ingo2=       ingo[_n-2] if imfcode==imfcode[_n-2]
	gen capopen2= capopen[_n-2] if imfcode==imfcode[_n-2]
	gen civlib2 =  civlib[_n-2] if imfcode==imfcode[_n-2]
	
	** generate 3-year lags:
	gen tradecontext3=tradecontext[_n-3] if imfcode==imfcode[_n-3]
	gen fdiflows3=fdiflows[_n-3] if imfcode==imfcode[_n-3]
	gen fdistock3=fdistock[_n-3] if imfcode==imfcode[_n-3]
	gen trade3=trade[_n-3] if imfcode==imfcode[_n-3]
	gen ngos3=ngos[_n-3] if imfcode==imfcode[_n-3]
	gen income3=income[_n-3] if imfcode==imfcode[_n-3]
	gen population3=population[_n-3] if imfcode==imfcode[_n-3]
	gen democracy3=democracy[_n-3] if imfcode==imfcode[_n-3]
	gen civilwar3=civilwar[_n-3] if imfcode==imfcode[_n-3]
	gen lawtradecontext3=lawtradecontext[_n-3] if imfcode==imfcode[_n-3]
	gen practicetradecontext3=practicetradecontext[_n-3] if imfcode==imfcode[_n-3]
	gen hardpta3=hardpta[_n-3] if imfcode==imfcode[_n-3]
	gen softpta3=softpta[_n-3] if imfcode==imfcode[_n-3]
	gen exports3=exports[_n-3] if imfcode==imfcode[_n-3]
	gen wlawpos3=wlawpos[_n-3] if imfcode==imfcode[_n-3]
	gen wpracticepos3=wpracticepos[_n-3] if imfcode==imfcode[_n-3]
	gen lawinstrument3=lawinstrument[_n-3] if imfcode==imfcode[_n-3]
	gen practiceinstrument3=practiceinstrument[_n-3] if imfcode==imfcode[_n-3]
	gen lawinstb3=lawinstb[_n-3] if imfcode==imfcode[_n-3]
	gen practiceinstb3=practiceinstb[_n-3] if imfcode==imfcode[_n-3]
	gen wlanglaw3=wlanglaw[_n-3] if imfcode==imfcode[_n-3]
	gen wlangprac3=wlangprac[_n-3] if imfcode==imfcode[_n-3]
	gen wrellaw3=wrellaw[_n-3] if imfcode==imfcode[_n-3]
	gen wrelprac3=wrelprac[_n-3] if imfcode==imfcode[_n-3]
	gen wcollaw3=wcollaw[_n-3] if imfcode==imfcode[_n-3]
	gen wcolprac3=wcolprac[_n-3] if imfcode==imfcode[_n-3]
	gen igo3=         igo[_n-3] if imfcode==imfcode[_n-3]
	gen ingo3=       ingo[_n-3] if imfcode==imfcode[_n-3]
	gen capopen3= capopen[_n-3] if imfcode==imfcode[_n-3]
	gen civlib3 =  civlib[_n-3] if imfcode==imfcode[_n-3]
			
sort imfcode year
merge m:1 imfcode using gattlist.dta 
drop if _m==2 
drop _merge
sort imfcode year
merge m:1 imfcode using wtolist.dta 
drop if _m==2 
drop _merge

gen gatt = year>=gattjoin
gen wto = year>=wtojoin
gen gattwto = gatt==1 | wto==1

gen study = ""
foreach n in orig noth fe time fet ct yfe cyfe {
gen method_`n' = ""
gen dv_`n' = ""
gen b_gatt_`n' = .
gen se_gatt_`n'= .
gen pval_gatt_`n' = .
gen lo_gatt_`n'=.
gen hi_gatt_`n'=.
gen N_gatt_`n'=.
}
gen studynum=.
gen timetrend=""
qui do gatt.do

local ii = 1
	** Now run the regressions
	xtset imfcode year

** Table 2:
* model 1
xtreg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust cluster(imfcode)
gatt `ii' orig
xtreg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust cluster(imfcode)
gatt `ii' noth
xtreg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust cluster(imfcode) fe
gatt `ii' fe
xtreg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 year, robust cluster(imfcode)
gatt `ii' time
xtreg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 year, robust cluster(imfcode) fe
gatt `ii' fet
reg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 i.imfcode#c.year,  cluster(imfcode) 
gatt `ii' ct

xtreg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 i.year , robust cluster(imfcode) fe
gatt `ii' cyfe
xtreg lawpos gattwto lawpos1 lawtradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust cluster(year) i(year)
gatt `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
xtset imfcode year
* model 2
xtreg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust cluster(imfcode)
gatt `ii' orig
xtreg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust cluster(imfcode)
gatt `ii' noth
xtreg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust cluster(imfcode) fe
gatt `ii' fe
xtreg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 year, robust cluster(imfcode)
gatt `ii' time
xtreg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 year, robust cluster(imfcode) fe
gatt `ii' fet
reg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 i.imfcode#c.year,  cluster(imfcode)
gatt `ii' ct

xtreg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 i.year, robust cluster(imfcode) fe
gatt `ii' cyfe
xtreg lawpos gattwto lawpos1 lawtradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust cluster(year) i(year)
gatt `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 3
xtset imfcode year
xtreg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust cluster(imfcode)
gatt `ii' orig
xtreg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust cluster(imfcode)
gatt `ii' noth
xtreg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust cluster(imfcode) fe
gatt `ii' fe
xtreg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 year, robust cluster(imfcode)
gatt `ii' time
xtreg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 year, robust cluster(imfcode) fe
gatt `ii' fet
reg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 i.imfcode#c.year,  cluster(imfcode) 
gatt `ii' ct

xtreg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 i.year, robust cluster(imfcode) fe
gatt `ii' cyfe
xtreg lawpos gattwto lawpos1 lawtradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust cluster(year) i(year)
gatt `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1

** Table 3:
* model 4
xtset imfcode year
xtreg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust cluster(imfcode)
gatt `ii' orig
xtreg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust cluster(imfcode)
gatt `ii' noth
xtreg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust fe cluster(imfcode)
gatt `ii' fe
xtreg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 year, robust cluster(imfcode)
gatt `ii' time
xtreg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 year, robust fe cluster(imfcode)
gatt `ii' fet
reg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 i.imfcode#c.year, cluster(imfcode)
gatt `ii' ct

xtreg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1 i.year, robust fe cluster(imfcode)
gatt `ii' cyfe
xtreg practicepos gattwto practicepos1 practicetradecontext1 fdiflows1 trade1 income1 population1 democracy1 civilwar1 hardpta1 softpta1, robust i(year) cluster(year)
gatt `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 5
xtset imfcode year
xtreg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust cluster(imfcode)
gatt `ii' orig
xtreg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust cluster(imfcode)
gatt `ii' noth
xtreg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust fe cluster(imfcode)
gatt `ii' fe
xtreg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 year, robust cluster(imfcode)
gatt `ii' time
xtreg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 year, robust fe cluster(imfcode)
gatt `ii' fet
reg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 i.imfcode#c.year,  cluster(imfcode)
gatt `ii' ct

xtreg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2 i.year, robust fe cluster(imfcode)
gatt `ii' cyfe
xtreg practicepos gattwto practicepos1 practicetradecontext2 fdiflows2 trade2 income2 population2 democracy2 civilwar2 hardpta2 softpta2, robust i(year) cluster(year)
gatt `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
* model 6
xtset imfcode year
xtreg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust cluster(imfcode)
gatt `ii' orig
xtreg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust cluster(imfcode)
gatt `ii' noth
xtreg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust fe cluster(imfcode)
gatt `ii' fe
xtreg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 year, robust cluster(imfcode)
gatt `ii' time
xtreg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 year, robust fe cluster(imfcode)
gatt `ii' fet
reg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 i.imfcode#c.year, cluster(imfcode)
gatt `ii' ct

xtreg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3 i.year, robust fe cluster(imfcode)
gatt `ii' cyfe
xtreg practicepos gattwto practicepos1 practicetradecontext3 fdiflows3 trade3 income3 population3 democracy3 civilwar3 hardpta3 softpta3, robust i(year) cluster(year)
gatt `ii' yfe
replace studynum = `ii' if _n==`ii'   
local ii=`ii'+1
replace study = "Greenhill et. al." if studynum~=. 	

keep study-timetrend
drop if studynum==.
compress
save greenhill.dta , replace

